var aFunc = {
	plusReady: function() {
		if (mui.os.plus) {
			plus.navigator.closeSplashscreen();
			plus.screen.lockOrientation("portrait-primary");
			plus.navigator.setStatusBarBackground(common.colour.statusBackground);
			_self = plus.webview.currentWebview();
			_self.setStyle({
				bounce: "none",
				// bounceBackground: common.colour.statusBackground
			});

			window.addEventListener('reloadHome', function(event) {
				aFunc.initData();
			});
		}
		aFunc.bindEvent();
		// aFunc.initView();
		// 进入页面
		window.addEventListener('enterPage', function(e) {
			aFunc.initView();
		});
		// 刷新页面
		window.addEventListener('reloadme', function(event) {
			aFunc.initView();
		});

		aFunc.initData();
		aFunc.back();

	},
	back: function() {
		mui.back = function(event) {
			aVariable.ipt.backButtonPress++;
			if (aVariable.ipt.backButtonPress > 1) {
				plus.runtime.quit();
			} else {
				plus.nativeUI.toast('再按一次退出应用');
			}
			setTimeout(function() {
				aVariable.ipt.backButtonPress = 0;
			}, 1000);
			return false;
		};
	},


	back: function() {
		mui.back = function(event) {
			aVariable.backButtonPress++;
			if (aVariable.backButtonPress > 1) {
				plus.runtime.quit();
			} else {
				plus.nativeUI.toast('再按一次退出应用');
			}
			setTimeout(function() {
				aVariable.backButtonPress = 0;
			}, 1000);
			return false;
		};
	},


	initData: function() {
		var name = LocalStorage.getItem(LocalStorage.keys.User_Name);
		if (name != null && name.length > 0) {
			aVariable.userinfo.name.innerHTML = name;
		}


		plus.runtime.getProperty(plus.runtime.appid, function(inf) {
			wgtVer = inf.version;
            aVariable.view.version.innerHTML = "版本"+wgtVer;
		});

	},



	bindEvent: function() {
		mui(".mui-table-view").on("tap", "li", function(data) {
			var card = this;
			var ID = card.getAttribute("data-id");

			var htmlID = "";
			var htmlPath = "";

			switch (ID) {
				case "person":
					break;
				case "about":
					htmlID = "about";
					htmlPath = "../../views/sys/about/about.html";
					break;
				case "setting":
					break;
				case "warehouse":
					htmlID = "side-select";
					htmlPath = "../../views/sys/side-select/side-select.html";
					break;
				case "loginout":
					aFunc.loginOut();
					break;
				default:
					break;
			}

			if (htmlPath.length == 0) {
				if (ID != "loginout") {
					mui.toast("页面不存在");
				}

				return;
			}

			// var opener = plus.webview.getWebviewById(plus.runtime.appid);
			// mui.fire(opener, 'menu:close"');

			mui.openWindow({
				id: htmlID,
				url: htmlPath,
				show: {
					aniShow: 'slide-in-right'
				},
				waiting: {
					autoShow: false
				}
			});
		});
	},

	loginOut: function() {
		var opener = plus.webview.getWebviewById(plus.runtime.appid);
		var btnArray = ['否', '是'];
		mui.confirm('是否退出登录？', '提示', btnArray, function(e) {
			if (e.index == 1) {
				mui.fire(opener, 'menu:close"');
				util.login_out();
				mui.openWindow({
					id: 'loginPage',
					url: '../../views/sys/login/login.html',
					styles: {
						popGesture: "none"
					},
					show: {
						aniShow: 'none'
					},
					waiting: {
						autoShow: false
					}
				});
			} else {}
		});
	},

	initView: function() {
		var userData = JSON.parse(LocalStorage.getItem(LocalStorage.keys.User_Info));
		if (userData) {
			aVariable.userinfo.name.innerHTML = userData.realName;
			if (userData.userType == 1) {
				aVariable.userinfo.type.innerHTML = "巡检员";
			} else {
				aVariable.userinfo.type.innerHTML = "管理员";
			}
		}
	},
};
